using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace JlPay.Sdk.Models.Openmerch.Bill
{
    /// <summary>
    /// 账单明细信息
    /// @author liaochangyi
    /// @since 2025-01-25
    /// </summary>
    public class BillDetail
    {
        /// <summary>
        /// 开始营业日期，yyyy-MM-dd
        /// </summary>
        [JsonPropertyName("start_busi_date")]
        public string? StartBusiDate { get; set; }

        /// <summary>
        /// 结束营业日期，yyyy-MM-dd
        /// </summary>
        [JsonPropertyName("end_busi_date")]
        public string? EndBusiDate { get; set; }

        /// <summary>
        /// 结算时间，yyyy-MM-dd
        /// </summary>
        [JsonPropertyName("bill_date")]
        public string? BillDate { get; set; }

        /// <summary>
        /// 备注，付款失败原因
        /// </summary>
        [JsonPropertyName("remark")]
        public string? Remark { get; set; }

        /// <summary>
        /// 付款状态：0-待付款 1-付款成功 2-付款失败 3-无需付款
        /// </summary>
        [JsonPropertyName("pay_status")]
        public string? PayStatus { get; set; }

        /// <summary>
        /// 付款金额
        /// </summary>
        [JsonPropertyName("pay_amt")]
        public string? PayAmt { get; set; }

        /// <summary>
        /// 交易笔数
        /// </summary>
        [JsonPropertyName("trans_count")]
        public string? TransCount { get; set; }

        /// <summary>
        /// 结算账户
        /// </summary>
        [JsonPropertyName("settle_account")]
        public string? SettleAccount { get; set; }

        /// <summary>
        /// 退票金额，单位：分
        /// </summary>
        [JsonPropertyName("refund_amount")]
        public string? RefundAmount { get; set; }

        /// <summary>
        /// 退票日期
        /// </summary>
        [JsonPropertyName("return_date")]
        public string? ReturnDate { get; set; }

        /// <summary>
        /// 退票原因
        /// </summary>
        [JsonPropertyName("return_reason")]
        public string? ReturnReason { get; set; }

        /// <summary>
        /// 退票卡号
        /// </summary>
        [JsonPropertyName("account_no")]
        public string? AccountNo { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public BillDetail()
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="detailDict">明细字典</param>
        public BillDetail(Dictionary<string, object>? detailDict)
        {
            if (detailDict != null)
            {
                StartBusiDate = detailDict.TryGetValue("start_busi_date", out var startBusiDate) ? startBusiDate?.ToString() : null;
                EndBusiDate = detailDict.TryGetValue("end_busi_date", out var endBusiDate) ? endBusiDate?.ToString() : null;
                BillDate = detailDict.TryGetValue("bill_date", out var billDate) ? billDate?.ToString() : null;
                Remark = detailDict.TryGetValue("remark", out var remark) ? remark?.ToString() : null;
                PayStatus = detailDict.TryGetValue("pay_status", out var payStatus) ? payStatus?.ToString() : null;
                PayAmt = detailDict.TryGetValue("pay_amt", out var payAmt) ? payAmt?.ToString() : null;
                TransCount = detailDict.TryGetValue("trans_count", out var transCount) ? transCount?.ToString() : null;
                SettleAccount = detailDict.TryGetValue("settle_account", out var settleAccount) ? settleAccount?.ToString() : null;
                RefundAmount = detailDict.TryGetValue("refund_amount", out var refundAmount) ? refundAmount?.ToString() : null;
                ReturnDate = detailDict.TryGetValue("return_date", out var returnDate) ? returnDate?.ToString() : null;
                ReturnReason = detailDict.TryGetValue("return_reason", out var returnReason) ? returnReason?.ToString() : null;
                AccountNo = detailDict.TryGetValue("account_no", out var accountNo) ? accountNo?.ToString() : null;
            }
        }

        /// <summary>
        /// 转换为字典格式
        /// </summary>
        /// <returns>字典数据</returns>
        public Dictionary<string, object?> ToDictionary()
        {
            return new Dictionary<string, object?>
            {
                ["start_busi_date"] = StartBusiDate,
                ["end_busi_date"] = EndBusiDate,
                ["bill_date"] = BillDate,
                ["remark"] = Remark,
                ["pay_status"] = PayStatus,
                ["pay_amt"] = PayAmt,
                ["trans_count"] = TransCount,
                ["settle_account"] = SettleAccount,
                ["refund_amount"] = RefundAmount,
                ["return_date"] = ReturnDate,
                ["return_reason"] = ReturnReason,
                ["account_no"] = AccountNo
            };
        }
    }
} 